package com.bqy.myokgo.base;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;

import com.bqy.myokgo.R;
import com.bqy.myokgo.base.manager.AppManager;
import com.bqy.myokgo.base.manager.DialogManager;

/**
 * Created by 熊猫先生 on 2018/10/19.
 */
public abstract class MyBaseActivity extends AppCompatActivity implements View.OnClickListener {

    /**
     * mToolBar 控制toolbar相关内容
     */
    public MyToolBarView mToolBar;

    /**
     * 子类显示区域
     */
    public FrameLayout mView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.default_activity_my_base);
        mToolBar = findViewById(R.id.context_toolbar);
        mView = findViewById(R.id.context_view);
        if (setContentView() != null) {
            mView.addView(setContentView());
        }
        AppManager.getInstance().addActivity(this);
        iniGreate(savedInstanceState);
        iniView();
        iniClick();
        iniData();
    }

    public abstract View setContentView();

    public void iniGreate(Bundle savedInstanceState) {

    }

    public void iniView() {

    }

    public void iniClick() {

    }

    public void iniData() {

    }

    public void setOnClick(int... ids) {
        for (int id : ids)
            findViewById(id).setOnClickListener(this);

    }

    public void setOnClick(View... views) {
        for (View view : views)
            view.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void onBackPressed() {
        AppManager.getInstance().finishActivity();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        DialogManager.getInstance().RemoveOkGoAll();
    }
}
